package com.xh.bussiness.course.service.impl;

import com.xh.bussiness.course.bean.request.PrepareLessonLogRequest;
import com.xh.bussiness.course.model.PrepareLessonLog;
import com.xh.bussiness.course.dao.PrepareLessonLogMapper;
import com.xh.bussiness.course.service.IPrepareLessonLogService;
import com.xh.core.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xh.core.bean.XhPage;
import com.xh.core.util.StringUtils;
import java.util.List;
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Jqm
 * @since 2021-02-05
 */
@Service
public class PrepareLessonLogServiceImpl extends BaseServiceImpl<PrepareLessonLogMapper, PrepareLessonLog> implements IPrepareLessonLogService {
    @Override
    public XhPage queryPrepareLessonLogPage(XhPage page, PrepareLessonLogRequest bean) {
        QueryWrapper qw=new QueryWrapper<PrepareLessonLog>();
        //拼装条件
        qw=prepareParams(bean, qw);

        return (XhPage) this.dao.selectPage(page,qw);
    }

    @Override
    public List queryPrepareLessonLog(PrepareLessonLogRequest bean) {
        QueryWrapper qw=new QueryWrapper<PrepareLessonLog>();
        //拼装条件
        qw=prepareParams(bean, qw);
        qw.orderByDesc("create_time");
        return this.dao.selectList(qw);
    }


    /**
     * 准备条件
     * @param bean
     * @param qw
     */
    private QueryWrapper prepareParams(PrepareLessonLogRequest bean, QueryWrapper qw) {
        if(bean.getIds()!=null&&bean.getIds().length>0){
            qw.in("id",bean.getIds());
        }
        if (StringUtils.isNotEmpty(bean.getPrepareLessonId())) {
            qw.eq("prepare_lesson_id",bean.getPrepareLessonId());
        }
        return qw;
    }
}
